package com.njtech.smartuniversity.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.njtech.smartuniversity.bean.AssistantBean;
import com.njtech.smartuniversity.bean.AssistantBeanExample;
import com.njtech.smartuniversity.dao.AssistantBeanMapper;
import com.njtech.smartuniversity.service.AssistantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by ritchie on 6/25/18
 */

@Service
public class AssistantServiceImpl implements AssistantService {

    @Autowired
    public AssistantBeanMapper mAssistantBeanMapper;

    @Override
    public AssistantBean select(int id) {

        return  mAssistantBeanMapper.select(id);
    }

    @Override
    public int update(AssistantBean areaBean) {
        Integer id = areaBean.getId();
        return  mAssistantBeanMapper.update(areaBean);
    }

    @Override
    public List<AssistantBean> getAllAssistant(int area_id) {
        AssistantBeanExample caseBeanExample = new AssistantBeanExample();
        AssistantBeanExample.Criteria criteria =caseBeanExample.createCriteria() ;
        if (area_id!=5){
        criteria.andSIUuidEqualTo(area_id);
        }
        criteria.andGImgGreaterThan(1);
        return mAssistantBeanMapper.selectByExample(caseBeanExample);
    }

    @Override
    public PageInfo<AssistantBean> getAssistantByPage(int pageNum, int pageSize,int area_id) {
        PageHelper.startPage(pageNum, pageSize);
        List<AssistantBean> list =getAllAssistant(area_id);//这个查询会分页
        return new PageInfo<>(list);
    }


    @Override
    public boolean deleteById(int id) {
        int result = mAssistantBeanMapper.delete(id);
        return result != 0;
    }

    @Override
    public int addAssistant(AssistantBean caseBean) {
        return mAssistantBeanMapper.insert(caseBean);
    }


    @Override
    public int countbyid(){return mAssistantBeanMapper.countbyid();}

    @Override
    public int selectsum(int id){return mAssistantBeanMapper.selectsum(id);}

    @Override
    public int countbytime(AssistantBean assistantBean){return mAssistantBeanMapper.countbytime(assistantBean);}

    @Override
    public int countByExample(int area,int type){
        AssistantBeanExample caseBeanExample = new AssistantBeanExample();
        AssistantBeanExample.Criteria criteria =caseBeanExample.createCriteria() ;
        if (area!=5){
            criteria.andSIUuidEqualTo(area);
        }
        if(type==1){
            criteria.andGImgGreaterThan(1);
        }else{
            criteria.andGImgEqualTo(type);
        }
        return mAssistantBeanMapper.countByExample(caseBeanExample);
    }

    @Override
    public List<AssistantBean> select4(int area){
        AssistantBeanExample caseBeanExample = new AssistantBeanExample();
        AssistantBeanExample.Criteria criteria =caseBeanExample.createCriteria() ;
        if (area!=5){
            criteria.andSIUuidEqualTo(area);
        }
        criteria.andGImgEqualTo(4);
        return mAssistantBeanMapper.selet4(caseBeanExample);
    }
}
